package com.door.erp.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.Region;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.door.erp.enums.OrderStatus;
import com.door.erp.model.Client;
import com.door.erp.model.Color;
import com.door.erp.model.DoorFrame;
import com.door.erp.model.DoorLeaf;
import com.door.erp.model.LineShape;
import com.door.erp.model.OrderItem;
import com.door.erp.model.Orders;
import com.door.erp.model.Product;
import com.door.erp.pager.Pager;
import com.door.erp.sevice.ColorService;
import com.door.erp.sevice.GenerateNumberService;
import com.door.erp.sevice.OrderItemService;
import com.door.erp.sevice.OrderService;
import com.door.erp.sevice.ProductService;


@Controller
public class OrdersController {
	
	private final Logger log = Logger.getLogger(OrdersController.class);
	@Resource(name="orderService")
	private OrderService orderService;
	
	
	@Resource(name="productService")
	private ProductService productService ; 
	
	@Resource(name = "colorService")
	private ColorService colorService;
	
	@Resource(name = "orderItemService")
	private OrderItemService orderItemService;
	
	@Resource(name = "generateNumberService")
	private GenerateNumberService  generateNumberService;

	@RequestMapping(value="/orders/listOrder")
	public ModelAndView listOrders(HttpServletRequest request,Pager pager){
		ModelAndView m = new ModelAndView();
		if(pager == null) {
			pager = new Pager();
		}
		Map<String,Object> param = new HashMap<String,Object>();
		HttpSession session = request.getSession();
		Client client = (Client)session.getAttribute("client");
		long clientId = client.getId();
		param.put("client.id", clientId);
		int totalCount = this.orderService.listOrdersCount(param);
		pager.setTotalCount(totalCount);
		List<Orders> list = orderService.listOrderByPage(param,pager);
		m.setViewName("orders/order_list");
		m.addObject("list", list);
		m.addObject("pager", pager);
		return m;
	}
	
	@RequestMapping(value="/orders/saveOrUpdateOrderForward")
	public ModelAndView saveOrUpdateOrderForward(HttpServletRequest request){
		ModelAndView m = new ModelAndView();
		String orderId = request.getParameter("orderId");
		Orders order  = null;
		if(orderId!=null){
			long lorderid = Long.parseLong(orderId);
			order = this.orderService.getObject(lorderid);
		}else{
			String orderNo =  generateNumberService.generateNum(null);
			order = new Orders();
			order.setOrderNo(orderNo);
		}
		m.addObject("order", order);
		m.setViewName("orders/add_orders");
		return m;
		
	}
	
	@RequestMapping(value="/orders/saveOrUpdateOrder")
	public ModelAndView saveOrUpdateOrder(HttpServletRequest request){
		ModelAndView m = new ModelAndView();
		try{
		String strOrderid = request.getParameter("orderid");
		String orderNo = request.getParameter("orderNo");
		String [] productid = request.getParameterValues("productid");
		String [] colorName = request.getParameterValues("colorName");
		String [] isNeedDoorFrame = request.getParameterValues("isNeedDoorFrame");
		String [] isNeedDoorLeaf = request.getParameterValues("isNeedDoorLeaf");
		String [] isNeedLineShape = request.getParameterValues("isNeedLineShape");
		String [] doorFrameAmount = request.getParameterValues("doorFrameAmount");
		String [] doorFrameLength = request.getParameterValues("doorFrameLength");
		String [] doorFrameWidth = request.getParameterValues("doorFrameWidth");
		String [] doorFrameThickness = request.getParameterValues("doorFrameThickness");
		String [] doorLeafAmount = request.getParameterValues("doorLeafAmount");
		String [] doorLeafLength = request.getParameterValues("doorLeafLength");
		String [] doorLeafWidth = request.getParameterValues("doorLeafWidth");
		String [] doorLeafThickness = request.getParameterValues("doorLeafThickness");
		String [] lineShapeAmount = request.getParameterValues("lineShapeAmount");
		String [] lineShapeName = request.getParameterValues("lineShapeName");
		String [] lineShapeRemark = request.getParameterValues("lineShapeRemark");
		String [] remark = request.getParameterValues("remark");
		
		long lOrderid = Long.parseLong(strOrderid);
		Orders order = new Orders();
		if(lOrderid==0){
			order.setOrderNo(orderNo);
			HttpSession session = request.getSession();
			Client client = (Client)session.getAttribute("client");
			order.setClient(client);
			order.setCreateTime(new Date());
			OrderItem oi = null;
			Product product = null;
			List<OrderItem> items = new ArrayList<OrderItem>();
			DoorFrame df = null;
			DoorLeaf dl = null;
			LineShape ls = null;
			for(int i = 0;i<productid.length;i++){
				oi = new OrderItem();
				product = productService.getObject(Long.parseLong(productid[i]));
				oi.setProduct(product);
				oi.setColor(colorName[i]);
				oi.setRemark(remark[i]);
				items.add(oi);
				if("true".equals(isNeedDoorFrame[i])){
					df = new DoorFrame();
					df.setAmount(Integer.parseInt(doorFrameAmount[i].equals("")?"0":doorFrameAmount[i]));
					df.setHeight(Float.parseFloat(doorFrameLength[i].equals("")?"0":doorFrameLength[i]));
					df.setWidth(Float.parseFloat(doorFrameWidth[i].equals("")?"0":doorFrameWidth[i]));
					df.setThickness(Float.parseFloat(doorFrameThickness[i].equals("")?"0":doorFrameThickness[i]));
					oi.setDoorframe(df);
				}
				if("true".equals(isNeedDoorLeaf[i])){
					dl= new DoorLeaf();
					dl.setAmount(Integer.parseInt(doorLeafAmount[i].equals("")?"0":doorLeafAmount[i]));
					dl.setHeight(Float.parseFloat(doorLeafLength[i].equals("")?"0":doorLeafLength[i]));
					dl.setWidth(Float.parseFloat(doorLeafWidth[i].equals("")?"0":doorLeafWidth[i]));
					dl.setThickness(Float.parseFloat(doorLeafThickness[i].equals("")?"0":doorLeafThickness[i]));
					oi.setDoorLeaf(dl);
				}
				if("true".equals(isNeedLineShape[i])){
					ls = new LineShape();
					ls.setAmount(Integer.parseInt(lineShapeAmount[i].equals("")?"0":lineShapeAmount[i]));
					ls.setName(lineShapeName[i]);
					ls.setRemark(lineShapeRemark[i]);
					oi.setLineShape(ls);
				}
			}
			order.setItems(items);
			order.setStatus(OrderStatus.WAIT_VERIFY);
			this.orderService.add(order);
			m.setViewName("orders/order_add_success");
		}
		}catch(Exception e){
			m.setViewName("orders/order_add_error");
			log.error(e);
		}
		return m;
	}
	
	@RequestMapping(value="/orders/listProduct")
	public ModelAndView listProducts(Pager pager){
		ModelAndView  m = new ModelAndView();
		if(pager == null){
			pager = new Pager();
		}
		Map<String,Object> param = new HashMap<String,Object>();
		int totalCount = this.productService.getValidateResultSetCount(param);
		pager.setTotalCount(totalCount);
		List<Product> products = productService.getValidateResultSet(param, pager);
		m.addObject("products", products);
		m.setViewName("orders/products_lookup");
		return m;
		
	}
	
	@RequestMapping(value="/orders/listColor")
	public ModelAndView listColors(Pager pager){
		ModelAndView  m = new ModelAndView();
		if(pager == null){
			pager = new Pager();
		}
		Map<String,Object> param = new HashMap<String,Object>();
		int count  = this.colorService.getValidateResultSetCount(param);
		pager.setTotalCount(count);
		List<Color> colors = this.colorService.getValidateResultSet(param, pager);
		m.setViewName("orders/colors_lookup");
		m.addObject("colors", colors);
		return m;
	}
	
	/*@RequestMapping(value="/orders/saveOrUpdateOrderItem")
	public ModelAndView saveOrUpdateOrderItem(HttpServletRequest request){
			ModelAndView mv = new ModelAndView("dwzresponse");
			String productId = request.getParameter("productid");
			String amount = request.getParameter("count");
			String height = request.getParameter("height");
			String width = request.getParameter("width");
			String length = request.getParameter("length");
			String colorId = request.getParameter("colorid");
			String orderid = request.getParameter("orderid");
			String orderItemId = request.getParameter("orderitemid");
			OrderItem orderItem = null;
			if(orderItemId == null||orderItemId.trim().length()==0){
				long orderId = Long.parseLong(orderid);
				orderItem = new OrderItem();
				Product product = this.productService.getObject(Long.parseLong(productId));
				Orders order = this.orderService.getObject(orderId);
				orderItem.setProduct(product);
				orderItem.setOrder(order);
				orderItem.setAmount(Integer.parseInt(amount));
				orderItem.setHeight(Float.parseFloat(height));
				orderItem.setWidth(Float.parseFloat(width));
				orderItem.setLength(Float.parseFloat(length));
				Color color = this.colorService.getObject(Long.parseLong(colorId));
				orderItem.setColor("");
				orderItemService.add(orderItem);
			}else{
				orderItem = this.orderItemService.getObject(Long.parseLong(orderItemId));
				Product product = this.productService.getObject(Long.parseLong(productId));
				orderItem.setProduct(product);
				orderItem.setAmount(Integer.parseInt(amount));
				orderItem.setHeight(Float.parseFloat(height));
				orderItem.setWidth(Float.parseFloat(width));
				orderItem.setLength(Float.parseFloat(length));
				Color color = this.colorService.getObject(Long.parseLong(colorId));
				orderItem.setColor("");
				orderItemService.modify(orderItem);
			}
			
			DwzResponse response = new DwzResponse();
			response.setCallbackType(DWZ.callbackType);
			response.setMessage(DWZ.message_OK);
			response.setStatusCode(DWZ.statusCode_OK);
			mv.addObject("response", response);
			return mv;
	}*/

	
/*	@RequestMapping(value="/orders/listOrderItem")
	public ModelAndView listOrderItem(@RequestParam(value="orderId") String orderId,@RequestParam(value="type") String type){
		
		ModelAndView m = new ModelAndView();
		long order_Id = Long.parseLong(orderId);
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("order.id", order_Id);
		List<OrderItem> orderItems = this.orderItemService.getAll(params);
		m.setViewName("orders/order_item_list");
		m.addObject("orderItems", orderItems);
		m.addObject("type", type);
		return m;
	}
	
	@RequestMapping(value="/orders/deleteOrderItem")
	public ModelAndView deleteOrderItem(@RequestParam(value="orderItemId") long orderItemId){
			ModelAndView mv = new ModelAndView("dwzresponse");
			this.orderItemService.delete(orderItemId);
			DwzResponse response = new DwzResponse();
			response.setCallbackType(DWZ.callbackType);
			response.setMessage(DWZ.message_OK);
			response.setStatusCode(DWZ.statusCode_OK);
			mv.addObject("response", response);
			return mv;
			
	}*/
	
/*	@RequestMapping(value="/orders/saveOrder")
	public ModelAndView saveOrder(@RequestParam(value="orderId") long orderId){
			ModelAndView mv = new ModelAndView("dwzresponse");
			Orders order = this.orderService.getObject(orderId);
			order.setStatus(OrderStatus.WAIT_VERIFY);
			this.orderService.modify(order);
			DwzResponse response = new DwzResponse();
			response.setCallbackType(DWZ.callbackType);
			response.setMessage(DWZ.message_OK);
			response.setStatusCode(DWZ.statusCode_OK);
			response.setNavTabId("myOrder");
			mv.addObject("response", response);
			return mv;
	}*/
	
	
	@RequestMapping(value="/orders/loadOrderItemFrag")
	public ModelAndView loadOrderItemFrag(HttpServletRequest request){
		ModelAndView mv= new ModelAndView();
		String orderid = request.getParameter("orderid");
		String itemIndex = request.getParameter("itemIndex");
		mv.setViewName("orders/order_item");
		mv.addObject("orderid", orderid);
		mv.addObject("itemIndex", itemIndex);
		return mv;
	}
	
	@RequestMapping(value="/orders/loadProducts")
	public ModelAndView loadProducts(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException, JSONException{
		String hql = "from Product";
		List<Product> products = productService.getAll(hql);
		
		PrintWriter pw = null;
				
		try {
			pw = response.getWriter();
			JSONArray ja = new JSONArray();
			JSONObject jo = null;
			for(Product product : products){
				jo = new JSONObject();
				jo.put("productid", product.getId());
				jo.put("label", product.getName());
				jo.put("height", product.getHeight());
				jo.put("length", product.getLength());
				jo.put("width", product.getWidth());
				jo.put("colorid", product.getColor().getId());
				jo.put("colorName", product.getColor().getCode());
				ja.put(jo);
			}
			pw.write(ja.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(pw!=null){
				pw.flush();
				pw.close();
			}
		}
		return null;
	}
	
	@RequestMapping("/orders/exportPage.do")
	public String exportPage(HttpServletRequest request) {
		return "orders/export";
	}
	
	@RequestMapping("/orders/export.do")
	public void export(HttpServletRequest request, HttpServletResponse response) {
		String beginTimeStr = request.getParameter("beginTime");
		String endTimeStr = request.getParameter("endTime");
		String orderStatusStr = request.getParameter("orderStatus");
		
		OutputStream os = null;
		
		//进行转码，使其支持中文文件名  
		String fileName = "orders";
        try {
			fileName = java.net.URLEncoder.encode("订单报表", "UTF-8");
		} catch (UnsupportedEncodingException e1) {
			fileName = "orders";
			e1.printStackTrace();
		}  
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xls");
		
		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet();  
		
		HSSFCellStyle style = workbook.createCellStyle();
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		
		HSSFCellStyle hcs = workbook.createCellStyle();
		hcs.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		hcs.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		//设置列宽
		sheet.setColumnWidth(0, 2000);
		sheet.setColumnWidth(1, 6000);
		sheet.setColumnWidth(2, 3000);
		sheet.setColumnWidth(3, 2000);
		sheet.setColumnWidth(4, 3000);
		sheet.setColumnWidth(5, 3000);
		sheet.setColumnWidth(6, 3000);
		sheet.setColumnWidth(7, 3000);
		sheet.setColumnWidth(8, 3000);
		sheet.setColumnWidth(9, 3000);
		sheet.setColumnWidth(10, 3000);
		sheet.setColumnWidth(11, 3000);
		sheet.setColumnWidth(12, 4000);
		sheet.setColumnWidth(13, 4000);
		sheet.setColumnWidth(14, 3000);
		sheet.setColumnWidth(15, 8000);
		//列名
		HSSFRow title = sheet.createRow(0);
		HSSFRow head = sheet.createRow(1);
		title.setHeight((short)400);
		head.setHeight((short)400);
		//合并第一行
		sheet.addMergedRegion(new Region((short)0, (short)4, (short)0, (short)7));
		sheet.addMergedRegion(new Region((short)0, (short)8, (short)0, (short)11));
		sheet.addMergedRegion(new Region((short)0, (short)12, (short)0, (short)14));
		//合并第一行和第二行合并
		sheet.addMergedRegion(new Region((short)0, (short)0, (short)1, (short)0));
		sheet.addMergedRegion(new Region((short)0, (short)1, (short)1, (short)1));
		sheet.addMergedRegion(new Region((short)0, (short)2, (short)1, (short)2));
		sheet.addMergedRegion(new Region((short)0, (short)3, (short)1, (short)3));
		sheet.addMergedRegion(new Region((short)0, (short)15, (short)1, (short)15));
		
		//序号
		HSSFCell num = title.createCell(0);
		num.setCellType(HSSFCell.CELL_TYPE_STRING);
		num.setCellValue("序号");
		num.setCellStyle(style);
		//款式
		HSSFCell productName = title.createCell(1);
		productName.setCellType(HSSFCell.CELL_TYPE_STRING);
		productName.setCellValue("款式");
		productName.setCellStyle(style);
		//颜色
        HSSFCell color = title.createCell(2);
        color.setCellType(HSSFCell.CELL_TYPE_STRING);
        color.setCellValue("颜色");
        color.setCellStyle(style);
        //数量
        HSSFCell amount = title.createCell(3);
        amount.setCellType(HSSFCell.CELL_TYPE_STRING);
        amount.setCellValue("数量");
        amount.setCellStyle(style);
        //门扇尺寸
        HSSFCell doorLeaf = title.createCell(4);
        doorLeaf.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorLeaf.setCellValue("门扇（洞）尺寸mm");
        //门套尺寸
        HSSFCell doorframe = title.createCell(8);
        doorframe.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorframe.setCellValue("门套尺寸mm");
        //线条
        HSSFCell lineShape = title.createCell(12);
        lineShape.setCellType(HSSFCell.CELL_TYPE_STRING);
        lineShape.setCellValue("线条");
        //备注
        HSSFCell remark = title.createCell(15);
        remark.setCellType(HSSFCell.CELL_TYPE_STRING);
        remark.setCellValue("备注");
        remark.setCellStyle(style);
        //门扇高度
        HSSFCell doorLeafHeight = head.createCell(4);
        doorLeafHeight.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorLeafHeight.setCellValue("高度");
        //门扇宽度
        HSSFCell doorLeafWidth = head.createCell(5);
        doorLeafWidth.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorLeafWidth.setCellValue("宽度");
        //门扇厚度
        HSSFCell doorLeafThickness = head.createCell(6);
        doorLeafThickness.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorLeafThickness.setCellValue("厚度");
        //门扇数量
        HSSFCell doorLeafAmount = head.createCell(7);
        doorLeafAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorLeafAmount.setCellValue("数量");
        //门框高度
        HSSFCell doorframeHeight = head.createCell(8);
        doorframeHeight.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorframeHeight.setCellValue("高度");
        //门框宽度
        HSSFCell doorframeWidth = head.createCell(9);
        doorframeWidth.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorframeWidth.setCellValue("宽度");
        //门框厚度
        HSSFCell doorframeThickness = head.createCell(10);
        doorframeThickness.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorframeThickness.setCellValue("厚度");
        //门框数量
        HSSFCell doorframeAmount = head.createCell(11);
        doorframeAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
        doorframeAmount.setCellValue("数量");
        //线条型号
        HSSFCell lineShapeName = head.createCell(12);
        lineShapeName.setCellType(HSSFCell.CELL_TYPE_STRING);
        lineShapeName.setCellValue("型号");
        //线条规格
        HSSFCell lineShapeRemark = head.createCell(13);
        lineShapeRemark.setCellType(HSSFCell.CELL_TYPE_STRING);
        lineShapeRemark.setCellValue("规格");
        //线条数量
        HSSFCell lineShapeAmount = head.createCell(14);
        lineShapeAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
        lineShapeAmount.setCellValue("数量");
        
        //获得订单列表
        List<Orders> orders = this.orderService.getOrdersByExport(beginTimeStr, endTimeStr, orderStatusStr);
        
        if(orders == null) {
        	try {
    			os = response.getOutputStream();
    			workbook.write(os);
    		} catch (IOException e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				os.flush();
    				os.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
        } else {
	        int i = 1;
	        HSSFRow row = null;
	        for(Orders order : orders) {
	        	for(OrderItem item : order.getItems()) {
		        	row = sheet.createRow(i);
		        	row.setHeight((short)400);
		        	
		        	num = row.createCell(0);
		        	num.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	num.setCellValue(String.valueOf(i));
		        	num.setCellStyle(hcs);
		        	
		        	productName = row.createCell(1);
		        	productName.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	productName.setCellValue(item.getProduct().getName());
		        	productName.setCellStyle(hcs);
		        	
		        	color = row.createCell(2);
		        	color.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	color.setCellValue(item.getColor());
		        	color.setCellStyle(hcs);
		        	
		        	amount = row.createCell(3);
		        	amount.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	amount.setCellValue("");
		        	amount.setCellStyle(hcs);
		        	
		        	doorLeafHeight = row.createCell(4);
		        	doorLeafHeight.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorLeafHeight.setCellValue(item.getDoorLeaf() == null ? "" : String.valueOf(item.getDoorLeaf().getHeight()));
		        	doorLeafHeight.setCellStyle(hcs);
		        	
		        	doorLeafWidth = row.createCell(5);
		        	doorLeafWidth.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorLeafWidth.setCellValue(item.getDoorLeaf() == null ? "" : String.valueOf(item.getDoorLeaf().getWidth()));
		        	doorLeafWidth.setCellStyle(hcs);
		        	
		        	doorLeafThickness = row.createCell(6);
		        	doorLeafThickness.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorLeafThickness.setCellValue(item.getDoorLeaf() == null ? "" : String.valueOf(item.getDoorLeaf().getThickness()));
		        	doorLeafThickness.setCellStyle(hcs);
		        	
		        	doorLeafAmount = row.createCell(7);
		        	doorLeafAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorLeafAmount.setCellValue(item.getDoorLeaf() == null ? "" : String.valueOf(item.getDoorLeaf().getAmount()));
		        	doorLeafAmount.setCellStyle(hcs);
		        	
		        	doorframeHeight = row.createCell(8);
		        	doorframeHeight.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorframeHeight.setCellValue(item.getDoorframe() == null ? "" : String.valueOf(item.getDoorframe().getHeight()));
		        	doorframeHeight.setCellStyle(hcs);
		        	
		        	doorframeWidth = row.createCell(9);
		        	doorframeWidth.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorframeWidth.setCellValue(item.getDoorframe() == null ? "" : String.valueOf(item.getDoorframe().getWidth()));
		        	doorframeWidth.setCellStyle(hcs);
		        	
		        	doorframeThickness = row.createCell(10);
		        	doorframeThickness.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorframeThickness.setCellValue(item.getDoorframe() == null ? "" : String.valueOf(item.getDoorframe().getThickness()));
		        	doorframeThickness.setCellStyle(hcs);
		        	
		        	doorframeAmount = row.createCell(11);
		        	doorframeAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	doorframeAmount.setCellValue(item.getDoorframe() == null ? "" : String.valueOf(item.getDoorframe().getAmount()));
		        	doorframeAmount.setCellStyle(hcs);
		        	
		        	lineShapeName = row.createCell(12);
		        	lineShapeName.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	lineShapeName.setCellValue(item.getLineShape() == null ? "" : String.valueOf(item.getLineShape().getName()));
		        	lineShapeName.setCellStyle(hcs);
		        	
		        	lineShapeRemark = row.createCell(13);
		        	lineShapeRemark.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	lineShapeRemark.setCellValue(item.getLineShape() == null ? "" : String.valueOf(item.getLineShape().getRemark()));
		        	lineShapeRemark.setCellStyle(hcs);
		        	
		        	lineShapeAmount = row.createCell(14);
		        	lineShapeAmount.setCellType(HSSFCell.CELL_TYPE_STRING);
		        	lineShapeAmount.setCellValue(item.getLineShape() == null ? "" : String.valueOf(item.getLineShape().getAmount()));
		        	lineShapeAmount.setCellStyle(hcs);
		        	
		            remark = row.createCell(15);
		            remark.setCellType(HSSFCell.CELL_TYPE_STRING);
		            remark.setCellValue(item.getRemark());
		            remark.setCellStyle(hcs);
		            
		        	i++;
	        	}
	        }
	        try {
				os = response.getOutputStream();
				workbook.write(os);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
        }
	}
	
}
